﻿''' <summary>
''' Bàn giao tài sản cố định
''' </summary>
''' <remarks></remarks>
Public Class HandoverDTO
    Inherits Handover_X

    Private _id As Integer 'Mã TS
    Private _shipper As String 'Người giao
    Private _recipient As String 'Người nhận
    Private _date As Date 'Thời gian
    Private _place As String 'Địa điểm
    Private _fatype As Integer 'Loại tài sản cố định
    Private _status As Integer 'Trạng thái chứng từ

    Private _behave As Integer

    Public Sub New(ByVal id As Integer, ByVal shipper As String, ByVal recipient As String, ByVal date1 As Date, ByVal place As String, ByVal fatype As Integer)
        MyBase.New()
        Me._id = id
        Me._shipper = shipper
        Me._recipient = recipient
        Me._date = date1
        Me._place = place
        Me._fatype = fatype
        Me._status = CONSTANT.STATUS._DRAFTS

        Me._behave = CONSTANT.BEHAVE_TYPE._INSERT

    End Sub

    Public Sub New(ByVal id As Integer)
        MyBase.New()
        Dim mySqlConnect As MySqlConnect = New MySqlConnect
        Dim aSql As String = "SELECT * FROM '" & MyBase.TABLE_NAME & "' WHERE '" & MyBase.COLUMN_NAME_id & "'=" & id & ""
        Dim da As DataTable = mySqlConnect.executeQuery(aSql)
        If (da Is Nothing) Then
            Return
        End If
        Me._id = CType(da.Rows(0)(MyBase.COLUMN_NAME_id), Integer)
        Me._shipper = CType(da.Rows(0)(MyBase.COLUMN_NAME_shipper), String)
        Me._recipient = CType(da.Rows(0)(MyBase.COLUMN_NAME_recipient), Integer)
        Me._date = CType(da.Rows(0)(MyBase.COLUMN_NAME_date), Date)
        Me._place = CType(da.Rows(0)(MyBase.COLUMN_NAME_place), Integer)
        Me._fatype = CType(da.Rows(0)(MyBase.COLUMN_NAME_fatype), Integer)
        Me._status = CType(da.Rows(0)(MyBase.COLUMN_NAME_status), Integer)

        Me._behave = CONSTANT.BEHAVE_TYPE._UPDATE
    End Sub


    Public Function save() As Boolean

        Dim aSql As String
        Dim mySqlConnect As MySqlConnect
        mySqlConnect = New MySqlConnect

        Select Case Me._behave
            Case CONSTANT.BEHAVE_TYPE._UPDATE
                aSql = "UPDATE " & MyBase.TABLE_NAME & " SET " & MyBase.COLUMN_NAME_id & " = " & Me._id & " "
                aSql += " ," & MyBase.COLUMN_NAME_shipper & " = " & Me._shipper & ""
                aSql += " ," & MyBase.COLUMN_NAME_recipient & " = " & Me._recipient & ""
                aSql += " ," & MyBase.COLUMN_NAME_date & " = " & Me._date & ""
                aSql += " ," & MyBase.COLUMN_NAME_place & " = " & Me._place & ""
                aSql += " ," & MyBase.COLUMN_NAME_fatype & " = " & Me._fatype & ""
                aSql += " ," & MyBase.COLUMN_NAME_status & " = " & Me._status & ""
                aSql += " WHERE " & MyBase.COLUMN_NAME_id & " = " & Me._id & " "
                Return mySqlConnect.executeUpdate(aSql)

            Case CONSTANT.BEHAVE_TYPE._INSERT
                aSql = "INSERT INTO " & MyBase.TABLE_NAME & "(" & MyBase.COLUMN_NAME_id & ", " & MyBase.COLUMN_NAME_shipper & ", " & MyBase.COLUMN_NAME_recipient & ", " & MyBase.COLUMN_NAME_date & ", " & MyBase.COLUMN_NAME_place & ", " & MyBase.COLUMN_NAME_fatype & ", " & MyBase.COLUMN_NAME_status & ")"
                aSql += "VALUES(" & Me._id & ", " & Me._shipper & ", " & Me._recipient & ", " & Me._date & ", " & Me._place & ", " & Me._fatype & ", " & Me._status & ")"
                Return mySqlConnect.executeUpdate(aSql)

            Case Else

        End Select
        Return True
    End Function

    Public Function delete() As Boolean
        Dim mySqlConnect As MySqlConnect
        mySqlConnect = New MySqlConnect
        Dim aSql As String
        aSql = "DELETE FROM " & MyBase.TABLE_NAME & ""
        aSql += " WHERE " & MyBase.COLUMN_NAME_id & " = " & Me._id & ""

        Return mySqlConnect.executeUpdate(aSql)
    End Function




    Public Property id() As Integer
        Get
            Return Me._id
        End Get
        Set(ByVal value As Integer)
            Me._id = value
        End Set
    End Property

    Public Property shipper() As String
        Get
            Return Me._shipper
        End Get
        Set(ByVal value As String)
            Me._shipper = value
        End Set
    End Property

    Public Property recipient() As String
        Get
            Return Me._recipient
        End Get
        Set(ByVal value As String)
            Me._recipient = value
        End Set
    End Property

    Public Property datetime() As Date
        Get
            Return Me._date
        End Get
        Set(ByVal value As Date)
            Me._date = value
        End Set
    End Property

    Public Property place() As String
        Get
            Return Me._place
        End Get
        Set(ByVal value As String)
            Me._place = value
        End Set
    End Property

    Public Property status() As Integer
        Get
            Return Me._status
        End Get
        Set(ByVal value As Integer)
            Me._status = value
        End Set
    End Property

End Class
